package common;



public class Point3D{
	public double x = 0;
	public double y = 0;
	public double z = 0;
	
	public Point3D(double x, double y, double z){
		this.x = x;
		this.y = y;
		this.z = z;
	}
	
	public Point3D clone(){
		return new Point3D(x,y,z);
	}
	
	public void copy(Point3D point){
		this.x = point.x;
		this.y = point.y;
		this.z = point.z;
	}
	public double norm(){
		return Math.sqrt(x*x + y*y + z*z);
	}
	
	public void normalize(){
		double len = Math.sqrt(x*x + y*y + z*z);
		x /= len;
		y /= len;
		z /= len;
	}
	public void normalize(double scalar){
		double len = Math.sqrt(x*x + y*y + z*z)/scalar;
		x /= len;
		y /= len;
		z /= len;
		
	}
	public void rotate(double ax, double ay, double az){
		double ct, st;
		double t;
		ct = Math.cos(ax);
		st = Math.sin(ax);
		t = ct * y - st * z;
		z = st * y + ct * z;
		y = t;
		
		ct = Math.cos(ay);
		st = Math.sin(ay);
		t = ct * x + st * z;
		z = ct * z - st * x;
		x = t;
		
		ct = Math.cos(az);
		st = Math.sin(az);
		t = ct * x - st * y;
		y = st * x + ct * y;
		x = t;
	}
	public void rotateAgainst(Point3D left, Point3D up, Point3D face){
		Point3D q = this.clone();
		this.x = q.x * left.x	+ q.y * left.y	+ q.z * left.z;
		this.y = q.x * up.x		+ q.y * up.y	+ q.z * up.z;
		this.z = q.x * face.x	+ q.y *	face.y 	+ q.z * face.z;
	}
	
	public void rotateWith(Point3D left, Point3D up, Point3D face){
		Point3D q = this.clone();
		this.x = q.x * left.x	+ q.y * up.x	+ q.z * face.x;
		this.y = q.x * left.y	+ q.y * up.y	+ q.z * face.y;
		this.z = q.x * left.z	+ q.y *	up.z 	+ q.z * face.z;
	}

	public void negative(){
		x = -x;
		y = -y;
		z = -z;
	}
	
	public void add(Point3D point){
		this.x += point.x;
		this.y += point.y;
		this.z += point.z;
	}

	public void sub(Point3D point){
		this.x -= point.x;
		this.y -= point.y;
		this.z -= point.z;
	}
	
	public void scale(double scalar){
		this.x *= scalar;
		this.y *= scalar;
		this.z *= scalar;
	}
	public void setValues(double x, double y, double z){
		this.x = x;
		this.y = y;
		this.z = z;
	}

}
